﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Common.Base.Test;

namespace HJProject
{
    public class TestForSimpleCaculator:TestBase
    {
        protected override string Title => "简单计算器之加减乘除！";

        private double num1;
        private double num2;
        private double operations;

        public void GetNum1(double num)
        {
            this.num1 = num;
        }
        public void GetNum2(double num)
        {
            this.num2 = num;
        }
        public void GetOperation(char operation)
        {
            this.operations = operation;
        }
        public void DoCalculate()
        {
            //判断操作符计算
            switch (this.operations)
            {
                case ('+'):
                    Console.WriteLine("{0} {1} {2} = {3} ", this.num1, this.operations, this.num2, this.num1 + this.num2);
                    break;
                case ('-'):
                    Console.WriteLine("{0} {1} {2} = {3} ", this.num1, this.operations, this.num2, this.num1 - this.num2);
                    break;
                case ('*'):
                    Console.WriteLine("{0} {1} {2} = {3} ", this.num1, this.operations, this.num2, this.num1 * this.num2);
                    break;
                case ('/'):
                    if (this.num2 != 0)
                    {
                        Console.WriteLine("{0} {1} {2} = {3} ", this.num1, this.operations, this.num2, this.num1 / this.num2);
                    }
                    else
                    {
                        Console.WriteLine("That's a mistake. The dividend can't be zero!");
                    }
                    break;
                default:
                    Console.WriteLine("Sorry, this calculation is not supported at the moment");
                    break;
            }
        }

        public override void OnRunTest()
        {
            while (true)
            {
                //数据输入
                Console.WriteLine("Please give the operand 1");
                double num1 = Convert.ToDouble(Console.ReadLine());

                Console.WriteLine("Please give the calculation operation you wish to do");
                char operations = Convert.ToChar(Console.ReadLine());

                Console.WriteLine("Please give the operand 2");
                double num2 = Convert.ToDouble(Console.ReadLine());

                GetNum1(num1);
                GetNum2(num2);
                GetOperation(operations);
                DoCalculate();
            }
        }
    }
}
